package com.yaowk.sfp.eoms.server.controller;

import com.yaowk.sfp.eoms.api.NotifyApi;
import com.yaowk.sfp.eoms.api.model.NotifyTarget;
import com.yaowk.sfp.eoms.server.service.INotifyTargetService;
import com.yaowk.sfp.utils.email.EmailUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class NotifyController implements NotifyApi {

    @Autowired
    private EmailUtils emailUtils;
    @Autowired
    private INotifyTargetService notifyTargetService;

    @Override
    @ApiOperation("发送消息给管理员")
    public void send(String message) {
        NotifyTarget notifyTarget = new NotifyTarget();
        notifyTarget.setType(NotifyTarget.Type.EMAIL.getValue());
        List<String> emails = notifyTargetService.findAllOfTarget(notifyTarget);
        emailUtils.sendSimpleMessage(emails, message, "服务器未知错误异常报警");
    }
}
